# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: U2722A_App.py
  @time: 2022/3/12 10:52
  @desc:
"""
from ATS.instrumentDriver.InstGenSMU.InstGenSMU_U2722A import InstGenSMU_U2722A
import time


class U2722A_App:
    _instance = None

    def __init__(self, name):
        self.u2722a = InstGenSMU_U2722A(name)

    @classmethod
    def get_instance(cls, name, info_dict):
        if not cls._instance:
            cls._instance = InstGenSMU_U2722A(name, info_dict)
        return cls._instance

    def get_idn(self):
        return self.u2722a.idn()

    def init(self):
        self.u2722a.init()

    def close_all_channel(self):
        for i in [1, 2, 3]:
            self.u2722a.close_all_channel(i)

    def set_voltage_range(self, channel=1, voltage_range="20V"):
        self.u2722a.set_voltage_range(channel, voltage_range)

    def set_current_nplc(self, nplc, channel=1):
        self.u2722a.set_current_nplc(nplc, channel)

    def set_current_range_limit(self, current_range: str, current_limit: float, channel: int = 1):
        self.u2722a.set_current_range_limit(current_range, current_limit, channel)

    def set_voltage(self, voltage, channel=1):
        self.u2722a.set_voltage(voltage, channel)

    def set_current(self, current, v_compliance, channel=1):
        self.u2722a.set_current(current, v_compliance, channel)

    def get_voltage_value(self, channel=1):
        return self.u2722a.measure_voltage(channel)

    def get_current_value(self, channel=1):
        mes = self.u2722a.measure_current(channel)
        return mes

    def output_state(self, state, channel=1):
        self.u2722a.output_state(state, channel)

    def trigger(self, tag):
        self.u2722a.trigger(tag)
